<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        function Foo(name) {
            this.name = name;
        }
        Foo.prototype.alertName = function() {
            //既然Foo.prototype是普通的对象，那也允许给它添加额外的属性alertName
            console.log(this.name);
        }
        var fn = new Foo('smyhvae');
        fn.printName = function() {
                console.log(this.name);
            }
            //测试
        fn.printName();
        fn.alertName();
    </script>
</body>

</html>